package com.zhiyun.service.impl;

import com.zhiyun.domain.LeaveMsg;
import com.zhiyun.mapper.LeaveMsgMapper;
import com.zhiyun.service.LeaveMsgService;
import com.zhiyun.util.Db;
import com.zhiyun.vo.Result;

import java.util.List;

/**
 * @author zc
 * @Date 2025/4/29 上午10:12
 */
public class LeaveMsgServiceImpl implements LeaveMsgService {
    LeaveMsgMapper leaveMsgMapper = Db.getMapper(LeaveMsgMapper.class);
    @Override
    public Result addLeaveMsg(LeaveMsg leaveMsg) {
        return Result.ok(leaveMsgMapper.insert(leaveMsg));
    }

    @Override
    public Result MyLeaveMsg(int userId) {
        return Result.ok(leaveMsgMapper.selectByUserId(userId));
    }

    @Override
    public Result listLeaveMsg() {
        List<LeaveMsg> list =  leaveMsgMapper.selectWithNull();
        return Result.ok(list);
    }

    @Override
    public Result updateLeaveMsg(LeaveMsg leaveMsg) {
        LeaveMsg oldLeaveMsg = leaveMsgMapper.selectByPrimaryKey(leaveMsg.getId());
        if (oldLeaveMsg == null) {
            return Result.fail("没有该条留言");
        }
        int rows = leaveMsgMapper.updateByPrimaryKey(leaveMsg);
        if (rows > 0){
            return Result.okMsg("回复成功");
        }else {
            return Result.fail("回复失败");
        }
    }


}
